<template>
  <view class="mine-container" :style="{height: `${clientHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info">
            <view class="u_title">
              用户名：{{ name }}
            </view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view>
      </view>
    </view>
	
    <view class="content-section">
      <view class="mine-actions grid col-4 text-center">
		<view class="action-item" @click="handleStore" v-if="hasOwnStore">
		  <view class="iconfont icon-user text-yellow icon"></view>
		  <text class="text">我的商店</text>
		</view>
        <view class="action-item" @click="handleJiaoLiuQun">
          <view class="iconfont icon-friendfill text-pink icon"></view>
          <text class="text">交流群</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-service text-blue icon"></view>
          <text class="text">在线客服</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-community text-mauve icon"></view>
          <text class="text">反馈社区</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-dianzan text-green icon"></view>
          <text class="text">点赞我们</text>
        </view>
      </view>
	  <view class="content-task">
		  <view class="content-card-title">
			我的订单
		  </view>
		  <u-grid :col="4">
			<u-grid-item>
			  <u-icon name="shopping-cart" color="#ff0000" :size="46" @click="$tab.navigateTo('/pages/cart/index')"></u-icon>
			  <view class="grid-text">购物车</view>
			</u-grid-item>
			<u-grid-item>
			  <u-icon name="rmb-circle" color="#ff0000" :size="46" @click="$tab.navigateTo(`/pages/order/index`)"></u-icon>
			  <view class="grid-text">待付款</view> 
			</u-grid-item>
			<u-grid-item>
				<!-- 已付款 -->
			  <u-icon name="order" color="#ff0000" :size="46" @click="$tab.navigateTo(`/pages/order/index`)"></u-icon>
			  <view class="grid-text">待收货</view>  
			</u-grid-item>
			<u-grid-item>
				<!-- 已签收 -->
			  <u-icon name="calendar" color="#ff0000" :size="46" @click="$tab.navigateTo(`/pages/order/index`)"></u-icon>
			  <view class="grid-text">待评价</view>
			</u-grid-item>
			<u-grid-item>
			  <u-icon name="close-circle" color="#ff0000" :size="46" @click="$tab.navigateTo(`/pages/order/index`)"></u-icon>
			  <view class="grid-text">退款/仲裁</view>
			</u-grid-item>
		  </u-grid>
		</view>
      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <u-icon name="account-fill" color="green" size="20" label="编辑资料"></u-icon>
          </view>
        </view>
		<view class="list-cell list-cell-arrow" @click="handleToAddress">
		  <view class="menu-item-box">
		    <u-icon name="list-dot" color="#2979ff" size="20" label="地址管理"></u-icon>
		  </view>
		</view>
		<view class="list-cell list-cell-arrow" @click="handleToMarkerter">
		  <view class="menu-item-box">
		    <u-icon name="level" color="#bbff61" size="20" label="成为店主"></u-icon>
		  </view>
		</view>
		<view class="list-cell list-cell-arrow" @click="handleBuilding">
		  <view class="menu-item-box">
		    <u-icon name="share" color="#26ffb0" size="20" label="分享"></u-icon>
		  </view>
		</view>
		<view class="list-cell list-cell-arrow" @click="handleBuilding">
		  <view class="menu-item-box">
		    <u-icon name="file-text-fill" color="red" size="20" label="晒单"></u-icon>
		  </view>
		</view>
        <view class="list-cell list-cell-arrow" @click="handleHelp">
          <view class="menu-item-box">
            <u-icon name="question-circle" color="#ff31d3" size="20" label="常见问题"></u-icon>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleAbout">
          <view class="menu-item-box">
            <u-icon name="heart" color="#ff9c2a" size="20" label="关于我们"></u-icon>
          </view>
        </view>
		<view class="list-cell list-cell-arrow" @click="handleToSetting">
		  <view class="menu-item-box">
		    <u-icon name="setting" color="#3e3e3e" size="20" label="系统设置"></u-icon>
		  </view>
		</view>
      </view>
	  
    </view>
	<view class="content-bottom">
		
	</view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
import navigateType from '../marketer/marketer'
  import {apiExistOwnStore} from '@/api/store.js'
  export default {
    data() {
      return {
		hasOwnStore:false,
		clientHeight: 0,
        name: this.$store.state.user.name,
        version: getApp().globalData.config.appInfo.version
      }
    },
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
	onLoad() {
		this.doJudgeExistOwnStore()
		this.getClineHeight()
	},
    methods: {
		doJudgeExistOwnStore(){
			apiExistOwnStore().then(res=>{
				this.hasOwnStore = res.data
			})
		},
		handleStore(){
			this.$tab.navigateTo("/pages/marketer/marketer-manage?navigateType="+navigateType.innerNavigate)
		},
		handleBuilding(){
			this.$modal.msg("模块正在建设中~")
		},
		handleStoreOrCustomerService(){
			// if(this.$store.getters.)
		},
		handleToMarkerter(){
			this.$tab.navigateTo("/pages/marketer/marketer-register")
		},
		getBarHeight(){
			const res = uni.getSystemInfoSync()
			if(res.platform==='ios'){
				return 44+res.statusBarHeight
			}else if(res.platform==='android'){
				return 48+res.statusBarHeight
			}else{
				return 0;
			}
		},
		getNavBarHeight(){
			const res = uni.getSystemInfoSync()
			if(res.platform==='ios'){
				return 44
			}else if(res.platform==='android'){
				return 48
			}else{
				return 0;
			}
		},
		//获取可视区域高度
		getClineHeight(){
			const res = uni.getSystemInfo({
				success:(res=>{
					// #ifdef H5
					this.clientHeight = res.windowHeight-this.getBarHeight();
					// #endif
					// #ifdef APP-PLUS
					this.clientHeight = res.windowHeight -uni.upx2px(80)-this.getBarHeight();
					// #endif
				})
			});
			
		},
	  handleToAddress(){
		this.$tab.navigateTo("/pages/address/index")  
	  },
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToEditInfo() {
        this.$tab.navigateTo('/pages/mine/info/edit')
      },
      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/pages/index')
          })
        })
      },
      handleHelp() {
        this.$tab.navigateTo('/pages/mine/help/index')
      },
      handleAbout() {
        this.$tab.navigateTo('/pages/mine/about/index')
      },
      handleJiaoLiuQun() {
        this.$modal.showToast('交流群已满')
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;
	
	.content-card-title{
		font-weight: 600;
		padding-left: 30rpx;
		padding-top: 20rpx;
		padding-bottom: 10rpx;
		font-size: 30rpx;
	}
    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: rgb(255, 212, 56);
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }
	.content-task{
		background-color: #fff;
		margin: 0 30rpx;
		border-radius: 30rpx;
		padding: 10rpx 0;
	}
    .content-section {
      position: relative;
      top: -50px;
      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
  .content-bottom{
	  height: 50px;
  }
</style>
